export default {
  name: "VcuTableToolbar",
  props: {
    size: String,
  },
  data() {
    return {};
  },
  watch: {},
  created() {},
  mounted() {},
  render(h) {
    const { $parent: $xetable, renderToobarItem, renderToobarSlot, size } = this;
    const { toolbarList, toolbarSlots } = $xetable;

    return h(
      "div",
      {
        class: ["vcu-table--toolbar-wrapper", "mb-5"],
      },
      [
        toolbarSlots && toolbarSlots.toolbarTop ? renderToobarSlot("toolbarTop") : null,
        h("div", { class: ["clearfix"] }, [
          h("div", { class: "fl" }, [
            toolbarSlots && toolbarSlots.toolbarBefore ? h("div", { class: ["vcu-table--toolbar-item"] }, renderToobarSlot("toolbarBefore")) : null,
            h("div", { class: ["vcu-table--toolbar-item"] }, [
              toolbarList.length
                ? h(
                    "v-button-group",
                    {
                      props: {
                        size: size,
                      },
                    },
                    [toolbarList.map((item) => renderToobarItem(item))]
                  )
                : null,
              toolbarSlots && toolbarSlots.toolbarAfter ? h("div", { class: ["vcu-table--toolbar-item"] }, renderToobarSlot("toolbarAfter")) : null,
            ]),
          ]),
          toolbarSlots && toolbarSlots.toolbarRight ? h("div", { class: ["fr"] }, renderToobarSlot("toolbarRight")) : null,
        ]),
        toolbarSlots && toolbarSlots.toolbarBottom ? h("div", { class: ["vcu-table--toolbar-bottom"] }, renderToobarSlot("toolbarBottom")) : null,
      ]
    );
  },
  methods: {
    renderToobarSlot(type) {
      const { $parent: $xetable } = this;
      const { toolbarSlots, $scopedSlots: scopedSlots } = $xetable;
      if (typeof toolbarSlots[type] == "string") {
        return scopedSlots[type]();
      } else {
        return toolbarSlots[type]();
      }
    },
    renderToobarItem(item) {
      const { $parent: $xetable, size } = this;
      const { showColumnModal, showFilterModal, operateRestore, exportExcel, emptyTableLists, showOptionColumnModal, filterFormData } = $xetable;
      switch (item) {
        case "import":
          return <v-button size={size}>导入</v-button>;
          break;
        case "export":
          return (
            <v-button size={size} onClick={exportExcel}>
              导出
            </v-button>
          );
          break;
        case "print":
          return <v-button size={size}>打印</v-button>;
          break;
        case "column":
          return (
            <v-button size={size} onClick={showColumnModal}>
              列选择
            </v-button>
          );
          break;
        case "columnSave":
          return (
            <v-button
              size={size}
              onClick={() => {
                showOptionColumnModal({ tableName: filterFormData.filterFindUrl });
              }}
            >
              选项
            </v-button>
          );
          break;
        case "filter":
          return (
            <v-button size={size} onClick={showFilterModal}>
              过滤
            </v-button>
          );
          break;
        case "restore":
          return (
            <v-button size={size} onClick={operateRestore}>
              还原
            </v-button>
          );
          break;
        case "empty":
          return (
            <v-button size={size} onClick={emptyTableLists}>
              清空
            </v-button>
          );
          break;
      }
      return null;
    },
  },
};
